-- Action -- 
do
    local NEWACT = Action({ priority = 11,  rmb = true })
    NEWACT.id = "I26RZ"
    NEWACT.str = "熔铸"
    NEWACT.fn = function(act)
        if act.target and act.invobject and act.target.components.i26egotool then
            return act.target.components.i26egotool:RZ(act.invobject)
        end
    end
    AddAction(NEWACT)
end
do
    local NEWACT = Action({ priority = 1,  rmb = true, instant = true, })
    NEWACT.id = "I26TR_MODE"
    NEWACT.str = "切换模式"
    NEWACT.fn = function(act)
        local item = act.invobject
        if item and item.components.i26egotool then
            return item.components.i26egotool:TrMode()
        end
    end
    AddAction(NEWACT)
end

do
    local NEWACT = Action({ priority = 11,  rmb = true, instant = true, })
    NEWACT.id = "I26_FLOWER_SACK_GIVE"
    NEWACT.str = "给予物品"
    NEWACT.fn = function(act)
        local item = act.invobject
        if act.target and act.invobject and act.target.components.i26_flower_sack_data then
            if act.target.components.i26_flower_sack_data:CanAcceptItem(item) then
                return act.target.components.i26_flower_sack_data:UpdateData(item)
            end
        end
    end
    AddAction(NEWACT)
end

AddStategraphActionHandler("wilson", ActionHandler(ACTIONS.I26RZ, "doshortaction"))
AddStategraphActionHandler("wilson_client", ActionHandler(ACTIONS.I26RZ, "doshortaction"))

AddStategraphActionHandler("wilson", ActionHandler(ACTIONS.I26_FLOWER_SACK_GIVE, "doshortaction"))
AddStategraphActionHandler("wilson_client", ActionHandler(ACTIONS.I26_FLOWER_SACK_GIVE, "doshortaction"))


-- 修改 USEITEM 的 ComponentAction
-- Action --
AddComponentAction("USEITEM", "equippable", function(inst, doer, target, actions, right)
    if not (right and (target:HasTag("i26_laotie") or target:HasTag("i26_flower_sack"))) then return end
    if target:HasTag("i26_laotie") then -- 老铁右键动作
        -- 获取熔铸模式
        local fusion_mode = TUNING.I26_FUSION_MODE
        local is_rz_laotie = TUNING.IS_RZ_LAOTIE
        -- 如果熔铸武器老铁，检查是否开启熔铸老铁
        if inst.prefab == "i26_laotie" and not is_rz_laotie then return end

        -- 检查是否是特殊物品（法杖等）
        local is_special = inst.prefab == "firestaff"
                or inst.prefab == "icestaff"
                or inst.prefab == "yellowstaff"
                or inst.prefab == "opalstaff"
                or inst:HasTag("i26rzjc")  -- 保留原有的标签检查

        if fusion_mode == "standard" then
            -- 标准模式：使用原有的标签检查
            if is_special then
                table.insert(actions, ACTIONS.I26RZ)
            end
        elseif fusion_mode == "unlimited" then
            -- unlimited模式：特殊物品或工具武器都可以
            if is_special
                    or inst:HasTag("weapon")
                    or inst:HasTag("tool")
                    or inst.components.weapon
                    or inst.components.tool
                    or inst.components.walkspeedmult then
                table.insert(actions, ACTIONS.I26RZ)
            end
        end
    elseif target:HasTag("i26_flower_sack") then
        table.insert(actions, ACTIONS.I26_FLOWER_SACK_GIVE)
    end

end)

AddComponentAction("INVENTORY", "i26egotool", function(inst, doer, actions) 
    if doer and inst.replica.equippable and inst.replica.equippable:IsEquipped() then
        table.insert(actions, ACTIONS.I26TR_MODE)
    end
end)


--AddComponentAction("USEITEM", "equippable", function(inst, doer, target, actions, right)
--    if not (right and target:HasTag("i26_flower_sack")) then return end
--    -- 添加给予物品
--    table.insert(actions, ACTIONS.I26_FLOWER_SACK_GIVE)
--end)
